package com.drive.service.serviceimpl;

import com.drive.bean.Student;
import com.drive.entity.PageResult;
import com.drive.mapper.StudentMapper;
import com.drive.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 往
 * 学员管理service实现类
 */
@Service
public class StudentServiceImpl implements StudentService{
    @Autowired
    private StudentMapper studentMapper;
    @Override
    //新增
    public void add(Student student) {
        studentMapper.add(student);
    }

    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        //调用分页插件传入currentPage 和 pageSize
        PageHelper.startPage(currentPage,pageSize);
        //通过条件查询数据
        Page<Student> page = studentMapper.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void delete(Integer id) {
        studentMapper.delete(id);
    }

    @Override
    public Student findById(Integer id) {
        return studentMapper.findById(id);
    }

    @Override
    public void edit(Student student) {
        studentMapper.edit(student);
    }

    @Override
    public List<Student> findAll() {
       return studentMapper.findAll();
    }

}
